package com.cqrt.mapper;

import com.alibaba.fastjson.JSONObject;
import com.cqrt.entity.PlanTime;
import com.cqrt.entity.RTPreConstraintDO;
import com.cqrt.vo.CalendarVO;
import com.cqrt.vo.TyppmPlanActiveVO;
import com.hustcad.plm.rpm.model.entity.plan.TyppmPlan;
import com.hustcad.plm.rpm.model.entity.plan.TyppmPlanActive;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.org.UserDO;
import com.ty.ppm.model.entity.job.Job;
import oracle.sql.TIMESTAMP;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface RTProjectMapper {

    void updateProjectTemplateStatus(BigInteger oid);

    @Select("select name from ty_user where oid=#{oid}")
    String getUserNameById(BigInteger oid);

    @Select("SELECT earlyfinish FROM ty_pj_planactivte WHERE oid =#{oid}")
    LocalDateTime selectFinishById(BigInteger oid);

    @Select("select oid from ty_pj_job where activityid=#{activityId}")
    BigInteger selectJobById(BigInteger activityId);

    List<BigInteger> selectProceedById(BigInteger boid);

    List<BigInteger> selectProceeJobById(@Param("proceeds") List<BigInteger> proceeds);

    @Select("select prjid from ty_pj_job where oid=#{curJobId}")
    BigInteger selectProjectById(BigInteger curJobId);

    @Select("select groupoid from ty_project where oid=TO_NUMBER(#{oid})")
    BigInteger selectGroupById(String oid);

    List<RTPreConstraintDO> selectPreconstraintById(String projectOid);

    void batchInsert(@Param("rtPreConstraintDOList")List<RTPreConstraintDO> rtPreConstraintDOList);

    void updateTaskDescription(@Param("taskOid")BigInteger taskOid, @Param("description")String description);

    void updateActiveDescription(@Param("taskOid")BigInteger taskOid, @Param("description") String description);

    List<RTPreConstraintDO> selectRelationsByMasterOid(BigInteger taskOid);

    List<RTPreConstraintDO> selectRelationsBySlaveOid(BigInteger taskOid);

    List<RTPreConstraintDO> selectByProjectOid(String projectOid);

    void batchDeleteRelations(@Param("relationIds")List<BigInteger> relationIds);

    boolean existSalveJob(String jobId);

    void fillCommnNewProject(String oid);

    void transExecutor(@Param("jobID")String jobID, @Param("executorOID")String executorOID);

    @Select("select * from TY_USER where FULLNAME=#{name} AND ROWNUM =1")
    UserDO selectUserByName(String name);

    @Select("select * from TY_USER where NAME=#{name} AND ROWNUM =1")
    UserDO selectUserByWorkName(String name);

    List<Job> batchSelectMasterStartDates(@Param("masterOids")List<BigInteger> masterOids);

    List<Job> batchSelectSlaveFinishDates(@Param("slaveOids")List<BigInteger> slaveOids);

    List<String> selectProjectByName(@Param("deleteProjectNumberList")List<String> deleteProjectNumberList);

    @Select("select ATTRIBUTEREFERENCEOID from TY_LOCALEPROPERTYVALUE where VALUE=#{name} AND MARKFORDELETE='0' AND HOLDREFERENCEOID=2230")
    BigInteger selectProjectTypeByName(String name);

    @Delete("delete from RT_PRJ_PRECONSTRAINT where APOID=#{projectOid}")
    void deleteRelations(String projectOid);

    boolean existProject(String projectOid);

    BigInteger selectPrByName(String name);

    @Select("select OID from TY_PJ_JOB where PRJID=TO_NUMBER(#{prj})")
    List<BigInteger> selectJobByOID(String prj);

    void updateJobPublish(@Param("jobList") List<BigInteger> jobList);

    BigInteger selectStageById(String jobOID);

    @Select("select * from TY_PJ_JOB where OID=#{stageJobOID}")
    Job selectStageJob(BigInteger stageJobOID);
    BigInteger selectParentJob(BigInteger stageJobOID);

    @Select("select DESCRIPTIONCONTAINERINFO from TY_PROJECT where OID=TO_NUMBER(#{oid})")
    String queryDescription(String oid);

    BigInteger selectGroupByPlanId(BigInteger planOid);

    void lockPlanById(@Param("planOid") BigInteger planOid, @Param("user") UserDO user);

    UserDO selectUserDetailByCode(String devCode);

    List<BigInteger> selectPlanById(@Param("jobId") List<BigInteger> jobId);

    void updateJobById(BigInteger jobID);

    IdentifierEntity selectTemplateSubFolderByName(@Param("name")String name);

    BigInteger selectPlanOidByOid(String jobOid);

    List<String> selectSubfolderByPushModeAndDevelopmentLevel(@Param("level")String level, @Param("pushMode")String pushMode);

    @MapKey("ATTRIBUTEENNAME")
    Map<String,Map<String,String>> selectAttributeAndValues(@Param("objId") String projectId);

    List<String> selectTemplateIdByPushModeAndDevelopmentLevel(@Param("level")String level, @Param("pushMode")String pushMode);

    String selectProjectDirectorGroupId(@Param("id") String oid);

    List<String> selectFinishJobByName(String name);

    Map<String, TIMESTAMP> selectPlanTimeById(String string);

    void updatePlanTime(PlanTime planTime);

    List<Map<String,String>> selectDevelopmentOrder(@Param("codes") List<String> codes);

    Map<String, Object> selectDetsMeasures(String code);

    Map<String, String> selectDevelopmentOrderByName(String name);
    Map<String, String> selectDevelopmentOrderByOrderName(String name);

    String selectProjectNameByProjectCode(String projectNo);

    String selectProjectNameByProjectOid(String projectOid);
    Map<String, Object> selectProjectByOid(String oid);

    LocalDateTime selectStartDateByOid(BigInteger oid);

    LocalDateTime selectEndDateByOid(BigInteger oid);

    //Map<String, String> selectDevelopmentOrderByCode(String developmentOrder);

    BigInteger selectTemplateByPlanOID(BigInteger oid);

    Map<String, String> selectMapByOid(BigInteger templateOid);

    BigInteger selectPlanOIDByProjectOID(String oldProjectOID);

    void insertOrder(BigInteger OID,BigInteger attrDefOID, String attrDefOType, BigInteger ObjectId, String ObjectType, String refObj, String value, String valuex);

    List<BigInteger> selectDomainByProjectOID(BigInteger projectOid);

    void insertGroup(BigInteger projectOid, String projectType, Timestamp createTime, BigInteger domainOid, String domainOType, String roleName, BigInteger oid, String oType);

    List<BigInteger> selectOidByMemberLink(String userOid);

    String selectProjectNameByDevCode(String devCode);

    List<BigInteger> selectProjectOidByName(String projectName);

    Object selectOidFromGroup(BigInteger projectOid, String projectType, BigInteger domainOid, String domainOType, String roleName, BigInteger oid, String oType);

    Map<String, String> selectDevelopmentOrderByProjectName(String name);

    List<BigInteger> checkUser(@Param("containerOid") BigInteger containerOid, @Param("userOid") BigInteger userOid);

    List<BigInteger> selectplanTemplate(String containerOid);

    LocalDateTime selectStartDateByPlanOID(BigInteger planOID);

    LocalDateTime selectEndDateByPlanOid(BigInteger planOID);

    String selectPlanNameByPlanOid(String planOid);

    void updatePlanName(String planOid, String planName);

    String selectProjectIdByPlanOid(String planOid);

    @MapKey("ATTRIBUTENAME")
    Map<String,Map<String,String>> selectTemplateAttributeAndValues(String projectId);

    void insertPermission(BigInteger aOid, String aOType, BigInteger bOid, String bOType, Date createStamp, Date updateStamp, Date modifyStamp, BigInteger creatorOid, String creatorOType, String oType, BigInteger oid);

    void deletePermission(BigInteger aOid, BigInteger bOid);


    List<BigInteger> selectPermission(BigInteger aOid, BigInteger bOid);

    String selectPlanIdByProjectId(@Param("projectId") String projectId);

    List<String> selectOrderIsExist(String attrDefOid,String developmentOrder);

    List<Map<String, String>> selectTemplatePushModeAndDevelopmentLevelisNon(String s);

    String selectStatusByProjectOid(BigInteger prjOid);

    UserDO selectUserByNumber(String manager);

    List<BigInteger> selectDevIfExist(String devCode);

    List<String> selectAllProjectIdentifier(@Param("keys") List<String> keys);

    List<String> selectProjectLeaderByProjectChgId(@Param("projectChgId") String projectChgId);

    BigInteger selectPMO(String pmo);
    //根据属性显示名称查询属性OID
    List<BigInteger> selectAttrByDisplayName(String displayName);

    List<BigInteger> selectProjectIdByCode(String projectCode);

    List<BigInteger> selectEnumOidByName(String projectDirector);

    List<BigInteger> selectGroupByName(String projectDirector, BigInteger containerOid);

    List<BigInteger> selectUserIdByGroupId(BigInteger bigInteger);
    List<TyppmPlanActive> selectPlanActiveByProjectId(BigInteger bigInteger);

    void updateDate(String oid, LocalDateTime startDate, LocalDateTime finishDate, LocalDateTime earlyStart, LocalDateTime earlyFinish, LocalDateTime lateStart, LocalDateTime lateFinish);

    TyppmPlan selectPlanByProjectId(BigInteger bigInteger);

    void updatePlanDate(String oidPlan, LocalDateTime startDatePlan, LocalDateTime finishDatePlan);

    List<BigInteger> selectCalendarLink(String calendarOid);

    CalendarVO selectCalendarInfoByOid(BigInteger bigInteger);

    void updateCalendar(BigInteger oid, LocalDateTime startDate, LocalDateTime endDate);

    List<String> selectRiskByBranchIdS(@Param("ids") List<String> ids);

    List<JSONObject> selectIssueFormData(@Param("ids") List<String> ids);

    void deleteDevelopmentOrder(String code);

    void updateJobDate(BigInteger jobOid, LocalDateTime startDateJob, LocalDateTime finishDateJob);

    void updateConstraintDate(String oid, LocalDateTime constraintDate);

    String selectSecurity(String oid, BigInteger attfOid);

    void updateSecurity(String oid, BigInteger attfOid, String value, String valuex);

    LocalDateTime selectMasterStartDates(BigInteger masterOid);

    LocalDateTime selectSlaveFinishDates(BigInteger slaveOid);

    void insertRelation(String otype, String ownerString, BigInteger principalOid, String principalType, BigInteger accessBit, BigInteger relobjectOid, String relobjectType,
                        BigInteger createrOid, Date createTime, Date updateTime, Date modifyTime,BigInteger oid);

    void insertRelations(BigInteger aoid, String aotype, BigInteger boid, String botype, BigInteger createrOid, BigInteger isvirtualrole, String name, BigInteger oid, String otype, String rolekey);

    void insertProjectAndTemplateLink(@Param("projectOid") String projectOid, @Param("templateOid") String templateOid);

    String selectProjectTemplateOidByProjectOid(@Param("projectOid") String projectOid);

    void insertJob(Job job);

    BigInteger selectPlanActiveByJobId(BigInteger oid);

    List<String> selectWorkName(BigInteger planActiveOid);

    BigInteger selectGroup(String man,BigInteger projectoid);

    String selectStateByJobOid(BigInteger joid);

}



